package com.hoyo.utils;

import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailUtils {
	
	public static void send(String subject, String content, String reciever) throws Exception{
		
		final Properties props = new Properties();
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.host", "smtp.qq.com");
		props.put("mail.smtp.port", "587");
		props.put("mail.user", "853976819@qq.com");
		props.put("mail.password", "njkvohvromrlbfbi");
		Authenticator authenticator = new Authenticator() {

			protected PasswordAuthentication getPasswordAuthentication() {
				String userName = props.getProperty("mail.user");
				String password = props.getProperty("mail.password");
				return new PasswordAuthentication(userName, password);
			}
		};
		Session mailSession = Session.getInstance(props, authenticator);
		Message message = new MimeMessage(mailSession);
		InternetAddress form = new InternetAddress(props
				.getProperty("mail.user"));
		message.setFrom(form);

		InternetAddress to = new InternetAddress(reciever);
		message.setRecipient(RecipientType.TO, to);

		message.setSubject(subject);
		message.setContent(content, "text/html;charset=UTF-8");

		Transport.send(message);
	}
}
